home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Golden Games / Amiga CD-Sensation - Ausgabe 2 - Golden Games (1996)(GTI - Schatztruhe)(DE)[!].iso / Various / WordSearch / src / wsearch1.c < prev   
C/C++ Source or Header  |  1991-06-06  |  3KB  |  127 lines

  1. #include <stdio.h>
  2. #include "wsearch.h"
  3. #include <exec/types.h>
  4. #include <proto/intuition.h>
  5. #include <proto/graphics.h>
  6.  
  7. /* globals */
  8. int w,px,py,filter,rot;
  9. char word[MAXWORD][MAXSIZE+1];
  10. char *key;
  11.  
  12. struct IntuitionBase *IntuitionBase;
  13. struct GfxBase *GfxBase;
  14.  
  15. int LINK=0;    /* turned off but should work */
  16.  
  17. void main()
  18.  {
  19.    int i,j,k,error,xs,xt,ys,yt,xi,yi;
  20.    char rotation[10];
  21.  
  22.     IntuitionBase = (struct IntuitionBase *)
  23.       OpenLibrary("intuition.library",0);
  24.     if(IntuitionBase == NULL) 
  25.     {
  26.     fprintf(stderr,"Couldn't Open Intuition.library\n");
  27.     return;
  28.     }
  29.     
  30.     GfxBase = (struct GfxBase *)
  31.       OpenLibrary("graphics.library",0);
  32.     if(GfxBase == NULL)
  33.     {
  34.     fprintf(stderr,"Couldn't Open Graphics.library\n");
  35.     return;
  36.     }
  37.    
  38.    printf("Enter a filter for valid directions\n");
  39.    scanf("%d",&filter);
  40.    if(filter==0) filter = 255;
  41.  
  42.    printf("Display Views\n1:(X+,Y+) 2:(X-,Y+) 3:(X+,Y-); 4:(X-,Y-)\n");
  43.    printf("5:(Y+,X+) 6:(Y-,X+) 7:(Y+,X-); 8:(Y-,X-)\n");
  44.    printf("ei. 135 would print 3 puzzles:\n");
  45.    printf(" 1 follows the key,3 flips the y axis,5 transposes xy values\n");
  46.  
  47.    scanf("%s",&rotation);
  48.  
  49.    printf("Enter puzzle dimensions (width height)\n");
  50.    scanf("%d %d",&px,&py);
  51.    px = px-1; py=py-1;
  52.  
  53.    key = (char *)calloc((px+1)*(py+1),sizeof(char));
  54.    if(key<=0)
  55.    {
  56.     fprintf(stderr,"Unable to allocate memory\n");
  57.     exit(0);
  58.    }
  59.  
  60.    for(i=0;i<=px;i++)
  61.       for(j=0;j<=py;j++)
  62.          Key(i,j) = ' ';
  63.  
  64.    printf("How many words do you have?\n");
  65.    scanf("%d",&w);
  66.    w = w - 1;
  67.  
  68.    printf("Enter the words:\n");
  69.    for(i=0;i<=w;i++)
  70.       scanf("%s",word[i]);
  71.    printf("Working\n");
  72.  
  73.    error = wsearch();
  74.    if(error!=0)
  75.     {
  76.       fprintf(stderr,"Cannot generate puzzle (a word won't fit)\n");
  77.       exit(0);
  78.     }
  79.  
  80.    printf("Key:\n");
  81.    for(j=0;j<=py;j++)
  82.     {
  83.       for(i=0;i<=px;i++)
  84.             printf("%c",Key(i,j));
  85.       printf("\n");
  86.     }
  87.    printf("\n");
  88.  
  89.    for(i=0;i<=px;i++)
  90.       for(j=0;j<=py;j++)
  91.          if(Key(i,j) == ' ')
  92.             Key(i,j) = (char)(randint(25)+65);
  93.  
  94.    printf("The Wordsearch(es):\n");
  95.    k = 0;
  96.    for(k=0;k<strlen(rotation);k++)
  97.     {
  98.       rot = rotation[k]-48;
  99.       if(rot<1||rot>8) continue;
  100.  
  101.       switch(rot)
  102.        {
  103.          case 1:xs=0 ;ys=0 ;xt=px+1;yt=py+1;xi= 1;yi= 1;break;
  104.          case 2:xs=px;ys=0 ;xt=-1  ;yt=py+1;xi=-1;yi= 1;break;
  105.          case 3:xs=0 ;ys=py;xt=px+1;yt=-1  ;xi= 1;yi=-1;break;
  106.          case 4:xs=px;ys=py;xt=-1  ;yt=-1  ;xi=-1;yi=-1;break;
  107.          case 5:xs=0 ;ys=0 ;xt=py+1;yt=px+1;xi= 1;yi= 1;break;
  108.          case 6:xs=0 ;ys=px;xt=py+1;yt=-1  ;xi= 1;yi=-1;break;
  109.          case 7:xs=py;ys=0 ;xt=-1  ;yt=px+1;xi=-1;yi= 1;break;
  110.          case 8:xs=py;ys=px;xt=-1  ;yt=-1  ;xi=-1;yi=-1;break;
  111.        }
  112.  
  113.       for(j=ys;j!=yt;j=j+yi)
  114.        {
  115.          for(i=xs;i!=xt;i=i+xi)
  116.           if(rot<5)
  117.                printf("%c",Key(i,j));
  118.           else
  119.                printf("%c",Key(j,i));
  120.          printf("\n");
  121.        }
  122.       printf("\n");
  123.     }
  124.    return;
  125.  }
  126.  
  127.